

/*
-----------------------------------------------------------------------------
This source file is part of Labor3D
(Labor 3D Graphics Engine)

Copyright (c) 2009-2020 Rock Mao
* creator : Rock Mao
* created : 2009-10-25   22:29
* filename: LaborShaderSemantic.cpp
-----------------------------------------------------------------------------
*/
#include "stdafx.h"

#include "LaborShaderSemantic.h"
#include "LaborShader.h"
#include <map>
#include "../Common/LaborHashString.h"
using namespace std;
NAMESPACE_LABOR3D_BEGIN

typedef map<int , eLShaderParamSemantic> ShaderParamSemanticMap;
static ShaderParamSemanticMap  __global_static_spsmap;

CLShaderSemanticTable::CLShaderSemanticTable()
{
	__insert(eL_SPS_WorldMatrix         ,  L"WorldMatrix");
	__insert(eL_SPS_ViewMatrix          ,  L"ViewMatrix");
	__insert(eL_SPS_ProjMatrix          ,  L"ProjectionMatrix");
	__insert(eL_SPS_WVPMatrix           ,  L"WVPMatrix");
	__insert(eL_SPS_WorldViewMatrix     ,  L"WorldViewMatrix");
	__insert(eL_SPS_ViewProjMatrix      ,  L"ViewProjectMatrix");
	__insert(eL_SPS_TextureMatrix       ,  L"TextureMatrix");
	__insert(eL_SPS_TextureMatrix0      ,  L"TextureMatrix0");
	__insert(eL_SPS_TextureMatrix1      ,  L"TextureMatrix1");
	__insert(eL_SPS_TextureMatrix2      ,  L"TextureMatrix2");
	__insert(eL_SPS_TextureMatrix3      ,  L"TextureMatrix3");
	__insert(eL_SPS_TextureMatrix4      ,  L"TextureMatrix4");
	__insert(eL_SPS_TextureMatrix5      ,  L"TextureMatrix5");
	__insert(eL_SPS_TextureMatrix6      ,  L"TextureMatrix6");
	__insert(eL_SPS_TextureMatrix7      ,  L"TextureMatrix7");


	__insert(eL_SPS_Inv_WorldMatrix     ,  L"InvWorldMatrix");
	__insert(eL_SPS_Inv_ViewMatrix      ,  L"InvViewMatrix");
	__insert(eL_SPS_Inv_ProjMatrix      ,  L"InvProjectionMatrix");
	__insert(eL_SPS_Inv_WVPMatrix       ,  L"InvWVPMatrix");
	__insert(eL_SPS_Inv_WorldViewMatrix ,  L"InvWorldViewMatrix");
	__insert(eL_SPS_Inv_ViewProjMatrix  ,  L"InvViewProjectionMatrix");


	__insert(eL_SPS_Camera_Pos          ,  L"CameraPos");
	__insert(eL_SPS_Camera_Up           ,  L"CameraUp");
	__insert(eL_SPS_Camera_Dir          ,  L"CameraDir");
	__insert(eL_SPS_Camera_Arg          ,  L"CameraArg"); 

	//Light info						 
	__insert(eL_SPS_LigthPos             , L"LightPostion");      
	__insert(eL_SPS_LightDiffuse         , L"LightDiffuse");
	__insert(eL_SPS_LightSpeculer        , L"LightSpeculer");
	__insert(eL_SPS_LightAmbient         , L"LightAmbient");
	__insert(eL_SPS_LightDir             , L"LightDirection");
	__insert(eL_SPS_LightCutoff          , L"LightCutoff");

	//Fog argument
	__insert(eL_SPS_FogColor             ,  L"FogColor");
	__insert(eL_SPS_FogArg               ,  L"FogArg");


	//Material							  
	__insert(eL_SPS_MatDiffuse           ,  L"MaterialDiffuse");
	__insert(eL_SPS_MatSpeculer          ,  L"MaterialSpeculer");
	__insert(eL_SPS_MatAmbient           ,  L"MaterialAmbient");
	__insert(eL_SPS_MatShiness           ,  L"MaterialShiness");

	//HDR								  
	__insert(eL_SPS_HDR_Exposure         ,  L"HDRExposure");
	__insert(eL_SPS_HDR_MiddleGray       ,  L"HDRMiddleGray");
	__insert(eL_SPS_Blom_Sharpness       ,  L"BlomSharpness");

	//Screen info						  
	__insert(eL_SPS_ScreenRes            ,  L"ScreenRes");
	__insert(eL_SPS_VPRes                ,  L"ViewportRes");
	//Geometry info
	__insert(eL_SPS_BoundBox             ,  L"BoundBox");

	//System info
	__insert(eL_SPS_Random               ,  L"Random");
	__insert(eL_SPS_RandOnce             ,  L"RandOnce");
	__insert(eL_SPS_TimeTickt            ,  L"TimeTickt");
	__insert(eL_SPS_FrameTime            ,  L"FrameTime");

	//texture info						  
	__insert(eL_SPS_TextureDim0        ,   L"TextureDim0");
	__insert(eL_SPS_TextureDim1        ,   L"TextureDim1");
	__insert(eL_SPS_TextureDim2        ,   L"TextureDim2");
	__insert(eL_SPS_TextureDim3        ,   L"TextureDim3");
	__insert(eL_SPS_TextureDim4        ,   L"TextureDim4");
	__insert(eL_SPS_TextureDim5        ,   L"TextureDim5");
	__insert(eL_SPS_TextureDim6        ,   L"TextureDim6");
	__insert(eL_SPS_TextureDim7        ,   L"TextureDim7");

}

CLShaderSemanticTable::~CLShaderSemanticTable()
{
	__global_static_spsmap.clear();
}

eLShaderParamSemantic CLShaderSemanticTable::parser(const wchar_t* paramName)
{
	int va = lStringHash(paramName);
	ShaderParamSemanticMap::iterator pos = __global_static_spsmap.find(va) ;
	if(pos == __global_static_spsmap.end() )
		return eL_SPS_NotUsed;
	return pos->second;
}

CLShaderSemanticTable& CLShaderSemanticTable::singleton()
{
	static CLShaderSemanticTable table;
	return table;
}

bool CLShaderSemanticTable::__insert(eLShaderParamSemantic _samantic , const wchar_t* paramName)
{
	int va =	lStringHash(paramName);
	if(__global_static_spsmap.find(va) != __global_static_spsmap.end() )
		return false;
	__global_static_spsmap.insert(ShaderParamSemanticMap::value_type(va , _samantic) ) ;
	return true;
}

NAMESPACE_LABOR3D_END